/**
 * Test algorithms for JettHoughts
 * 
 * Created 12/02/2012
 * 
 * @author Vasili Svirski
 * @version 0.01
 */

package com.jetthoughts.algorithms;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *  Among two words beginning by the same letter, but in different registers,
 *  the word with a capital letter, should go to the left.
 *   
 */
public class SortWords {

	public static List<String> Sort(String input) {

		Comparator<String>	comparator = new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				for(int i =0; i< o1.length(); i++){
					char c1 = o1.charAt(i);
					char c2 = o2.charAt(i);

					if ( Character.toLowerCase(c1) > Character.toLowerCase(c2) )
						return 1;
					if ( Character.toLowerCase(c1) < Character.toLowerCase(c2) )
						return -1;
					if ( Character.toLowerCase(c1) == Character.toLowerCase(c2) )
						if (c1 > c2) return 1;
						else return -1;
				}
				return 0;
			}
		};

		List<String> wordsArray = new ArrayList<String>();

		for (String value : input.split(" ")) {
			wordsArray.add(value);
		}

		Collections.sort(wordsArray, comparator); 

		return wordsArray;
	}
}